package com.hejie.commentservice.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SwaggerConfig {

    /**
     * 配置API文档
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                // 只扫描有@ApiOperation注解的方法
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                // 扫描评论服务的控制器包
                .apis(RequestHandlerSelectors.basePackage("com.hejie.commentservice.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置API文档基本信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("评论服务API文档")
                .description("视频平台评论服务的API接口文档，包含评论的添加、查询、更新、删除等操作")
                .contact(new Contact("视频平台开发团队", "https://example.com", "contact@example.com"))
                .version("1.0.0")
                .build();
    }
}